﻿<%@ Page Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="EditUser.aspx.cs" 
         Inherits="EditUser" Title="&#1040;&#1090;&#1072;&#1084;&#1072;&#1085; &#1084;&#1077;&#1073;&#1077;&#1083;&#1100;: &#1056;&#1077;&#1076;&#1072;&#1082;&#1090;&#1080;&#1088;&#1086;&#1074;&#1072;&#1085;&#1080;&#1077; &#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1077;&#1083;&#1103;"  %>
<script runat="server">
    
    public void AssignUserToRoles_Activate(object sender, EventArgs e)
    {
        // Databind list of roles in the role manager system to listbox
        AvaliableRoles.DataSource = Roles.GetAllRoles(); 
        AvaliableRoles.DataBind();
    }

    public void btn_OnClick(object sender, EventArgs e)
    {
        Roles.AddUserToRole(UsersList.SelectedValue.ToString(), AvaliableRoles.SelectedValue.ToString());
        Response.Redirect("Users.aspx");
    }

    public void btn_DeleteClick (object sender, EventArgs e)
    {
        Membership.DeleteUser(UsersList.SelectedValue, true);
        Response.Redirect("Users.aspx");
    }       
</script>
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
    <div id="pagetitle">&#1056;&#1077;&#1076;&#1072;&#1082;&#1090;&#1080;&#1088;&#1086;&#1074;&#1072;&#1085;&#1080;&#1077; &#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1077;&#1083;&#1103;</div>
        <div class="userProfile">
        <div class="clear">
            <div class ="userPersonalInfo">
                <h1>&#1048;&#1079;&#1084;&#1077;&#1085;&#1077;&#1085;&#1080;&#1077; &#1087;&#1077;&#1088;&#1089;&#1086;&#1085;&#1072;&#1083;&#1100;&#1085;&#1086;&#1081; &#1080;&#1085;&#1092;&#1086;&#1088;&#1084;&#1072;&#1094;&#1080;&#1080; &#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1077;&#1083;&#1103;</h1>
                <div class="logName">
                    <asp:Label ID="lbllogName" AssociatedControlID="AvaliableRoles" Text="&#1059;&#1095;&#1105;&#1090;&#1085;&#1072;&#1103; &#1079;&#1072;&#1087;&#1080;&#1089;&#1100;:" runat="server" />
                    <asp:ListBox ID="UsersList" DataSourceID="ObjectDataSource2" runat="server" DataValueField="UserName" CssClass="loginList" />
                    <asp:ObjectDataSource ID="ObjectDataSource2" runat="server" 
                        DataObjectTypeName="System.Web.Security.MembershipUser" 
                        SelectMethod="GetAllUsers" TypeName="System.Web.Security.Membership">
                    </asp:ObjectDataSource>
                </div>
                <div class="userRole">
                    <asp:Label ID="lblRole" AssociatedControlID="AvaliableRoles" Text="&#1056;&#1086;&#1083;&#1100;:" runat="server" CssClass="roleLabel" />
                    <asp:ListBox ID="AvaliableRoles" runat="server" SelectionMode="Single"  OnInit="AssignUserToRoles_Activate" CssClass="roleList" />
                </div>
            </div>
           <div class="userProfileDetails">
           <%--     <div class="nameForm">
                    <asp:Label ID="NameLabel" runat="server" AssociatedControlID="Name1" Text="&#1048;&#1084;&#1103;:" CssClass="label" />
                    <asp:TextBox ID="Name1" runat="server" CssClass="form" />
                </div>
                <div class="surnameForm">
                    <asp:Label ID="SurnameLabel" runat="server" AssociatedControlID="Surname1" CssClass="label" Text="&#1060;&#1072;&#1084;&#1080;&#1083;&#1080;&#1103;:" />
                    <asp:TextBox ID="Surname1" runat="server" CssClass="form" />
                </div>
                <div class="lastNameForm"> 
                    <asp:Label ID="LastNameLabel" runat="server" AssociatedControlID="LastName1" Text="&#1054;&#1090;&#1095;&#1077;&#1089;&#1090;&#1074;&#1086;:" CssClass="label" />
                    <asp:TextBox ID="LastName1" runat="server" CssClass="form" />
                </div>
                <div class="phoneForm">                 
                    <asp:Label ID="PhoneLabel" runat="server" AssociatedControlID="Phone1" Text="&#1058;&#1077;&#1083;&#1077;&#1092;&#1086;&#1085;:" CssClass="label" />
                    <asp:TextBox ID="Phone1" runat="server" CssClass="form" />
                </div>--%>
                <asp:Button ID="btnUpdate" runat="server" Text="&#1048;&#1079;&#1084;&#1077;&#1085;&#1080;&#1090;&#1100;" OnClick="btn_OnClick" />
                <asp:Button ID="btnDelete" Text="&#1059;&#1076;&#1072;&#1083;&#1080;&#1090;&#1100; &#1087;&#1086;&#1083;&#1100;&#1079;&#1086;&#1074;&#1072;&#1090;&#1077;&#1083;&#1103;" OnClick="btn_DeleteClick" runat="server" />
                 </div>
            <%--            <h3>Delete User</h3>

            <asp:Label id="Msg" ForeColor="maroon" runat="server" /><br />

  <p style="color:red">Are you sure you want to delete the userid <b>User.Identity.Name</b>?</p>

  <asp:Button id="YesButton" Text="Yes" OnClick="btn_DeleteClick" runat="server" />
  <asp:Button id="CancelButton" Text="Cancel" runat="server" />
--%>
              
                 <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
                SelectMethod="DeleteUser" TypeName="System.Web.Security.Membership" 
                    OldValuesParameterFormatString="original_{0}" DeleteMethod="Delete" >
                     <SelectParameters>
                         <asp:ControlParameter ControlID="UsersList" Name="username" 
                             PropertyName="SelectedValue" Type="String" />
                         <asp:Parameter DefaultValue="true" Name="deleteAllRelatedData" Type="Boolean" />
                     </SelectParameters>
            </asp:ObjectDataSource>
                <%--</div>--%>
       </div>
    </div>
</asp:Content>

